<?php
/**
 * Created by PhpStorm.
 * User: asus
 * Date: 2017/2/26
 * Time: 13:42
 */

namespace Home\Controller;


use Home\Model\VipModel;
use Think\Controller;

class CommonController extends Controller
{
    public function __construct()
    {
        parent::__construct();
        if(!$_SESSION['admin']['user']){
            $this->error('请登录',u('Login/index'));
        }
        $num = (new VipModel())->count();
        $this->assign('num',$num);
    }



    public function dd($data){
        echo "<pre/>";
        print_r($data);
        die;
    }

    /**
     * @param $model 要分页的模型类
     * @param $num   每页显示数量
     * @param $order 排序方法
     */
    public function page($model,$num,$order)
    {
        $user = $model;

        $count      = $user->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,$num);// 实例化分页类 传入总记录数和每页显示的记录数(25)

        //print_r($Page);
//        $Page->setConfig('header',"共 {$Page->totalRows} 条文章");

        $Page->setConfig('theme',"%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $show       = $Page->show();// 分页显示输出

        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = $user->order($order)->limit($Page->firstRow.','.$Page->listRows)->select();
        //$this->dd($list);
        //$this->dd($list);
//        echo '<pre>';
//        print_r($list);die;
        $this->assign('list',$list);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出
    }
}